package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.SearchMessageListResult;
import com.net.wanjian.networkhospitalmanager.utils.DateUtil;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;
import com.zhy.autolayout.utils.AutoUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by lidongcai on 17/7/5.
 * Email:  lidongcaiocc@163.com
 */

public class MessageListAdapter extends RecyclerBaseAdapter<SearchMessageListResult.DataBean.MessageListBean, MessageListAdapter.ViewHolder> {

    public MessageListAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_notification, parent, false);
        AutoUtils.auto(view);
        return new ViewHolder(view);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, SearchMessageListResult.DataBean.MessageListBean item, int position) {

        holder.setItemNotificationContentTv(URLDecoderUtil.getDecoder(item.getMessageContentText()));

        String replace = URLDecoderUtil.getDecoder(item.getMessageContentCreateDate()).replace("/", "-");

        holder.setItemNotificationDateTv(DateUtil.friendlyFormat(replace));

        switch (item.getMessageReadState()) {
            case "0"://未读
                holder.setItemNotificationImgIv(false);
                break;
            case "1"://已读
                holder.setItemNotificationImgIv(true);
                break;
        }
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_notification_img_iv)
        ImageView itemNotificationImgIv;
        @BindView(R.id.item_notification_title_tv)
        TextView itemNotificationTitleTv;
        @BindView(R.id.item_notification_date_tv)
        TextView itemNotificationDateTv;
        @BindView(R.id.item_notification_content_tv)
        TextView itemNotificationContentTv;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        //设置值的方法

        public void setItemNotificationImgIv(boolean b) {
            if (b) {
                this.itemNotificationImgIv.setSelected(true);
            } else {
                this.itemNotificationImgIv.setSelected(false);
            }
        }

        /*public void setItemNotificationTitleTv(String itemNotificationTitleTv) {
            this.itemNotificationTitleTv.setText(itemNotificationTitleTv);
        }*/

        public void setItemNotificationDateTv(String itemNotificationDateTv) {
            this.itemNotificationDateTv.setText(itemNotificationDateTv);
        }

        public void setItemNotificationContentTv(String itemNotificationContentTv) {
            this.itemNotificationContentTv.setText(itemNotificationContentTv);
        }
    }

}
